/*
package com.itheima.reggie.utils;

import com.itheima.reggie.entity.Employee;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Field;
import java.time.LocalDateTime;

@Aspect
@Component
public class AopAdvice {

    @Autowired
    private HttpSession session;

    @Pointcut("execution( * com.itheima.reggie.controller.*Controller.add*(..))")
    public void pt(){}


    @Before("pt()")
    public void setCommontProperties(JoinPoint jp) throws Exception {

        Object[] args = jp.getArgs();
        Object target = args[0];




        Class<?> aClass = target.getClass();
        Field field = aClass.getDeclaredField("createTime");
        field.setAccessible(true);
        field.set(target,LocalDateTime.now());

        field = aClass.getDeclaredField("updateTime");
        field.setAccessible(true);
        field.set(target,LocalDateTime.now());


        Employee loginEmployee = (Employee) session.getAttribute("loginEmployee");
        Long id = loginEmployee.getId();

        field = aClass.getDeclaredField("createUser");
        field.setAccessible(true);
        field.set(target,id);

        field = aClass.getDeclaredField("updateUser");
        field.setAccessible(true);
        field.set(target,id);


    }
}
*/
